<?php
/**
 * 后台管理控制器
 * 使用前origin参数不能是*，要设置成固定跨域请求域名
*/

namespace app\http\controller;
use houze\controller\Http;

/**
 * @Controller(prefix="")
*/
class Admin extends Http
{
    // 中间件
    public function run(){
        $request = \houze\context\Request::get();
        // 权限校验
        if(!empty($request->header['authorization'])){
            $token = str_replace('Bearer ', '', $request->header['authorization']);
            $userInfo = \houze\Session::get('admin_user_info');
            if(isset($userInfo['token'])){
                $status = $userInfo['token'] == $token ? true : false;
                if(!$status) $this->api(0, '令牌已失效，请重新登录！', []);
            }else{
                $this->api(0, '令牌已失效，请重新登录！', []);
            }
            return $userInfo;
        }else{
            $this->api(0, '令牌已失效，请重新登录！', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/login", method="post", title="登录")
    */
    public function system_login() {
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        if(!isset($param['username'])) return $this->api(0, '用户名没有输入', []);
        if(!isset($param['password'])) return $this->api(0, '密码没有输入', []);
        $Db = new \houze\Db();
        // 判断用户是否存在
        $user = $Db->table('system_user')->where('username', $param['username'])->find();
        if($user){
            if($user['password'] != $param['password']){
                return $this->api(0, '密码错误', []);
            }else{
                $Jwt = new \houze\Jwt();
                $token = $Jwt->create_token();
                $session = \houze\Session::set('admin_user_info', ['token'=>$token, 'user_id'=>$user['id']]);
                // 计入日志
                $Db = new \houze\Db();
                $Db->table('system_login_log')->insertGetId(['username'=>$param['username'], 'ip'=>\houze\Request::ip(), 'login_time'=>date("Y-m-d H:i:s", time())]);
                return $this->api(200, '请求成功', ['token'=>$token]);
            }
        }else{
            return $this->api(0, '账号不存在', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/logout", method="post", title="退出登录")
    */
    public function system_logout() {
        \houze\Session::delete('admin_user_info');
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/common/getNoticeList", method="get", title="公共获取公告信息")
    */
    public function system_common_getNoticeList() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取用户列表
        $data = $Db->table('system_notice')->paginate(5)->list();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/common/getLoginLogList", method="get", title="公共获取登录日志信息")
    */
    public function system_common_getLoginLogList() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取用户列表
        $data = $Db->table('system_login_log')->paginate(5)->list();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/getInfo", method="get", title="获取用户信息")
    */
    public function system_getInfo() {
        $config = $this->getUserMenuInfo();
        return $this->api(200, '请求成功', $config);
    }
    
    /**
     * @RequestMapping(route="/admin/system/dataDict/list", method="get", title="获取数据状态")
    */
    public function system_dataDict_list() {
        // 权限校验
        $authInfo = $this->run();
        
        $data = [
            ["id"=>7,"title"=>"正常","key"=>"1"],
            ["id"=>8,"title"=>"停用","key"=>"2"],
        ];
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/index", method="get", title="获取用户列表信息")
    */
    public function system_user_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取用户列表
        $data = $Db->table('system_user')->select();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/save", method="post", title="添加用户")
    */
    public function system_user_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        if(isset($param['role_ids'])) $role = $param['role_ids'];unset($param['role_ids']);
        if(isset($param['post_ids'])) $post = $param['post_ids'];unset($param['post_ids']);
        
        $Db = new \houze\Db();
        
        if($Db->table('system_user')->where('username', $param['username'])->find()) return $this->api(0, '用户已存在', []);
        
        // 添加用户
        $resultId = $Db->table('system_user')->insertGetId($param);
        if($resultId){
            // 添加角色关联
            if(isset($role)){
                foreach($role as $k => $v){
                    $Db->table('system_user_role')->insert(['user_id'=>$resultId, 'role_id'=>$v]);
                }
            }
            // 添加岗位关联
            if(isset($post)){
                foreach($role as $k => $v){
                    $Db->table('system_user_post')->insert(['user_id'=>$resultId, 'post_id'=>$v]);
                }
            }
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '添加失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/delete", method="delete", title="删除用户")
    */
    public function system_user_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            // 删除用户
            $result = $Db->table('system_user')->where('id', $v)->delete();
            // 删除角色关联
            $Db->table('system_user_role')->where('user_id', $v)->delete();
            // 删除岗位关联
            $Db->table('system_user_post')->where('user_id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/update", method="post", title="修改用户资料")
    */
    public function system_user_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        
        $Db = new \houze\Db();
        if(isset($param['username'])) $arr['username'] = $param['username'];
        if(isset($param['password'])) $arr['password'] = $param['password'];
        if(isset($param['user_type'])) $arr['user_type'] = $param['user_type'];
        if(isset($param['nickname'])) $arr['nickname'] = $param['nickname'];
        if(isset($param['phone'])) $arr['phone'] = $param['phone'];
        if(isset($param['email'])) $arr['email'] = $param['email'];
        if(isset($param['avatar'])) $arr['avatar'] = $param['avatar'];
        if(isset($param['signed'])) $arr['signed'] = $param['signed'];
        if(isset($param['dashboard'])) $arr['dashboard'] = $param['dashboard'];
        if(isset($param['dept_id'])) $arr['dept_id'] = $param['dept_id'];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        // 删除所有关联
        $Db->table('system_user_role')->where('user_id', $param['id'])->delete();
        if (isset($param['role_ids'])) {
            
            foreach ($param['role_ids'] as $k => $v){
                // 添加新关联
                $Db->table('system_user_role')->insert(['user_id'=>$param['id'], 'role_id'=>$v]);
            }
        }
        // 删除所有关联
        $Db->table('system_user_post')->where('user_id', $param['id'])->delete();
        if (isset($param['post_ids'])) {
            foreach ($param['post_ids'] as $k => $v){
                // 添加新关联
                $Db->table('system_user_post')->insert(['user_id'=>$param['id'], 'post_id'=>$v]);
            }
        }
        
        $Db->table('system_user')->where('id', $param['id'])->update($arr);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/updateInfo", method="post", title="修改用户信息")
    */
    public function system_user_updateInfo() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['nickname'])) $arr['nickname'] = $param['nickname'];
        if(isset($param['phone'])) $arr['phone'] = $param['phone'];
        if(isset($param['signed'])) $arr['signed'] = $param['signed'];
        if(isset($param['email'])) $arr['email'] = $param['email'];
        
        $Db = new \houze\Db();
        $Db->table('system_user')->where('id', $param['id'])->update($arr);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/modifyPassword", method="post", title="修改用户密码")
    */
    public function system_user_modifyPassword() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::param();
    
        $arr = [];
        if(isset($param['data_newPassword'])) $arr['password'] = $param['data_newPassword'];
        
        $Db = new \houze\Db();
        if(!$Db->table('system_user')->where('id', $param['id'])->where('password', $param['data_oldPassword'])->find()) return $this->api(0, '旧密码错误', []);
        $Db->table('system_user')->where('id', $param['id'])->update($arr);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/changeStatus", method="post", title="修改用户状态")
    */
    public function system_user_changeStatus() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        
        $Db = new \houze\Db();
        $Db->table('system_user')->where('id', $param['id'])->update($arr);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/user/read", method="get", title="读取单个用户信息")
    */
    public function system_user_read() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::param();
        
        $Db = new \houze\Db();
        $data = $Db->table('system_user')->where('id', $param['id'])->find();
        // 判断是否存在关联角色
        $role = $Db->table('system_user_role')->where('user_id', $param['id'])->select();
        foreach ($role as $k => $v){
            if(!isset($data['roleList'])) $data['roleList'] = [];
            array_push($data['roleList'], $Db->table('system_role')->where('id', $v['role_id'])->find());
        }
        // 判断是否存在关联岗位
        $post = $Db->table('system_user_post')->where('user_id', $param['id'])->select();
        foreach ($post as $k => $v){
            if(!isset($data['postList'])) $data['postList'] = [];
            array_push($data['postList'], $Db->table('system_post')->where('id', $v['post_id'])->find());
        }
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/menu/index", method="get", title="获取菜单首页信息")
    */
    public function system_menu_index() {
        $data = $this->getUserMenuInfo()['routers'];
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/menu/tree", method="get", title="获取菜单目录信息")
    */
    public function system_menu_tree() {
        // 权限校验
        $authInfo = $this->run();
        
        $data = $this->getTree('menu');
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/menu/save", method="post", title="添加菜单")
    */
    public function system_menu_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        if(!isset($param['parent_id'])) $param['parent_id'] = 0; 
        if(isset($param['route'])) $param['path'] = '/'.$param['route'];
        unset($param['restful']);
        
        $Db = new \houze\Db();
        // 添加用户
        $result = $Db->table('system_menu')->insert($param);

        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '添加失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/menu/delete", method="delete", title="删除菜单")
    */
    public function system_menu_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            // 删除用户
            $result = $Db->table('system_menu')->where('id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/menu/update", method="post", title="更新菜单")
    */
    public function system_menu_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['parent_id'])) $arr['parent_id'] = $param['parent_id'];
        if(isset($param['level'])) $arr['level'] = $param['level'];
        if(isset($param['name'])) $arr['name'] = $param['name'];
        if(isset($param['code'])) $arr['code'] = $param['code'];
        if(isset($param['icon'])) $arr['icon'] = $param['icon'];
        if(isset($param['path'])) $arr['path'] = $param['path'];
        if(isset($param['route'])) $arr['route'] = $param['route'];
        if(isset($param['component'])) $arr['component'] = $param['component'];
        if(isset($param['redirect'])) $arr['redirect'] = $param['redirect'];
        if(isset($param['is_hidden'])) $arr['is_hidden'] = $param['is_hidden'];
        if(isset($param['type'])) $arr['type'] = $param['type'];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        if(isset($param['sort'])) $arr['sort'] = $param['sort'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $result = $Db->table('system_menu')->where('id', $param['id'])->update($arr);
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '更新失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/menu/numberOperation", method="post", title="菜单数学运算")
    */
    public function system_menu_numberOperation() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        $result = $Db->table('system_menu')->where('id', $param['id'])->update([$param['numberName']=>$param['numberValue']]);
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '更新失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/index", method="get", title="获取角色首页信息")
    */
    public function system_role_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取角色信息
        $data = $Db->table('system_role')->select();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/list", method="get", title="获取角色列表信息")
    */
    public function system_role_list() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取角色信息
        $data = $Db->table('system_role')->select();
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/save", method="post", title="添加角色")
    */
    public function system_role_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        // 添加用户
        $result = $Db->table('system_role')->insert($param);

        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '添加失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/delete", method="delete", title="删除角色")
    */
    public function system_role_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            // 删除菜单关联
            $Db->table('system_role_menu')->where('role_id', $v)->delete();
            // 删除部门关联
            $Db->table('system_role_dept')->where('role_id', $v)->delete();
            // 删除角色
            $result = $Db->table('system_role')->where('id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/update", method="post", title="修改角色")
    */
    public function system_role_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['name'])) $arr['name'] = $param['name'];
        if(isset($param['code'])) $arr['code'] = $param['code'];
        if(isset($param['data_scope'])) $arr['data_scope'] = $param['data_scope'];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        if(isset($param['sort'])) $arr['sort'] = $param['sort'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $result = $Db->table('system_role')->where('id', $param['id'])->update($arr);
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '更新失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/getMenuByRole", method="get", title="获取角色关联菜单")
    */
    public function system_role_getMenuByRole() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::param();
        $Db = new \houze\Db();
        $data = $Db->table('system_role_menu')->where('role_id', $param['id'])->select();
        $menuArr = [];
        foreach ($data as $k => $v){
            array_push($menuArr, ['id'=>$v['menu_id'], 'pivot'=>$v]);
        }
        $data = [
            'id' => $param['id'],
            'menus' => $menuArr
        ];
        return $this->api(200, '请求成功', [$data]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/getDeptByRole", method="get", title="获取角色关联部门")
    */
    public function system_role_getDeptByRole() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::param();
        $Db = new \houze\Db();
        $data = $Db->table('system_role_dept')->where('role_id', $param['id'])->select();
        $menuArr = [];
        foreach ($data as $k => $v){
            array_push($menuArr, ['id'=>$v['dept_id'], 'map'=>$v]);
        }
        $data = [
            'id' => $param['id'],
            'depts' => $menuArr
        ];
        return $this->api(200, '请求成功', [$data]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/menuPermission", method="post", title="设置角色关联菜单")
    */
    public function system_role_menuPermission() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $get = \houze\Request::param();
        $param = json_decode($param, true);
        $Db = new \houze\Db();
        
        // 删除所有关联
        $Db->table('system_role_menu')->where('role_id', $get['id'])->delete();
        foreach ($param['menu_ids'] as $k => $v){
            // 添加关联
            $data = $Db->table('system_role_menu')->insert(['role_id'=>$get['id'], 'menu_id'=>$v]);
        }
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/role/dataPermission", method="post", title="设置角色关联部门")
    */
    public function system_role_dataPermission() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $get = \houze\Request::param();
        $param = json_decode($param, true);
        $Db = new \houze\Db();
        
        // 删除所有关联
        $Db->table('system_role_dept')->where('role_id', $get['id'])->delete();
        // 设置当前数据范围
        $Db->table('system_role')->where('id', $get['id'])->update(['data_scope'=>$param['data_scope']]);
        foreach ($param['dept_ids'] as $k => $v){
            // 添加关联
            $data = $Db->table('system_role_dept')->insert(['role_id'=>$get['id'], 'dept_id'=>$v]);
        }
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/dept/index", method="get", title="获取部门列表信息")
    */
    public function system_dept_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取部门信息
        $data = $Db->table('system_dept')->select();
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/dept/tree", method="get", title="获取部门目录")
    */
    public function system_dept_tree() {
        // 权限校验
        $authInfo = $this->run();
        
        $data = $this->getTree('dept');
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/dept/save", method="post", title="添加部门")
    */
    public function system_dept_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        if(!empty($param['parent_id'])) $param['parent_id'] = 0;
        
        $Db = new \houze\Db();
        // 添加用户
        $result = $Db->table('system_dept')->insert($param);

        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '添加失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/dept/delete", method="delete", title="删除部门")
    */
    public function system_dept_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            // 删除用户
            $result = $Db->table('system_dept')->where('id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/dept/update", method="post", title="修改部门")
    */
    public function system_dept_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['parent_id'])) $arr['parent_id'] = $param['parent_id'];
        if(isset($param['level'])) $arr['level'] = $param['level'];
        if(isset($param['name'])) $arr['name'] = $param['name'];
        if(isset($param['leader'])) $arr['leader'] = $param['leader'];
        if(isset($param['phone'])) $arr['phone'] = $param['phone'];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        if(isset($param['sort'])) $arr['sort'] = $param['sort'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $result = $Db->table('system_dept')->where('id', $param['id'])->update($arr);
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '更新失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/post/index", method="get", title="获取岗位首页信息")
    */
    public function system_post_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取岗位信息
        $data = $Db->table('system_post')->select();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/post/list", method="get", title="获取岗位列表信息")
    */
    public function system_post_list() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取岗位信息
        $data = $Db->table('system_post')->select();
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/system/post/save", method="post", title="添加岗位")
    */
    public function system_post_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        if(!empty($param['parent_id'])) $param['parent_id'] = 0;
        
        $Db = new \houze\Db();
        // 添加用户
        $result = $Db->table('system_post')->insert($param);

        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '添加失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/post/delete", method="delete", title="删除岗位")
    */
    public function system_post_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            // 删除用户
            $result = $Db->table('system_post')->where('id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/post/update", method="post", title="修改岗位")
    */
    public function system_post_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['name'])) $arr['name'] = $param['name'];
        if(isset($param['code'])) $arr['code'] = $param['code'];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        if(isset($param['sort'])) $arr['sort'] = $param['sort'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $result = $Db->table('system_post')->where('id', $param['id'])->update($arr);
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '更新失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/attachment/index", method="get", title="获取附件列表信息")
    */
    public function system_attachment_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取附件信息
        $data = $Db->table('system_uploadfile')->select();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/notice/index", method="get", title="获取系统公告列表信息")
    */
    public function system_notice_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取公告信息
        $data = $Db->table('system_notice')->select();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/notice/save", method="post", title="添加系统公告列表信息")
    */
    public function system_notice_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        $data = $Db->table('system_notice')->insert($param);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/notice/delete", method="delete", title="删除系统公告列表信息")
    */
    public function system_notice_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        foreach ($param['ids'] as $k => $v){
            $data = $Db->table('system_notice')->where('id', $v)->delete();
        }
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/notice/update", method="post", title="更新系统公告列表信息")
    */
    public function system_notice_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $arr = [];
        if(isset($param['message_id'])) $arr['message_id'] = $param['message_id'];
        if(isset($param['title'])) $arr['title'] = $param['title'];
        if(isset($param['type'])) $arr['type'] = $param['type'];
        if(isset($param['content'])) $arr['content'] = $param['content'];
        if(isset($param['click_num'])) $arr['click_num'] = $param['click_num'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $result = $Db->table('system_notice')->where('id', $param['id'])->update($arr);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/system/dictType/index", method="get", title="获取字典类型信息")
    */
    public function system_dictType_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取数据字典信息
        $data = $Db->table('system_dict_type')->select();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/dictType/save", method="post", title="字典类型添加")
    */
    public function system_dictType_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        // 添加用户
        $result = $Db->table('system_dict_type')->insert($param);

        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '添加失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/dictType/delete", method="delete", title="删除字典类型")
    */
    public function system_dictType_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            // 删除用户
            $result = $Db->table('system_dict_type')->where('id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/dictType/update", method="post", title="修改字典类型")
    */
    public function system_dictType_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['name'])) $arr['name'] = $param['name'];
        if(isset($param['code'])) $arr['code'] = $param['code'];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $Db->table('system_dict_type')->where('id', $param['id'])->update($arr);
        
        return $this->api(200, '请求成功', []);

    }
    
    /**
     * @RequestMapping(route="/admin/system/dataDict/index", method="get", title="获取字典数据信息")
    */
    public function system_dataDict_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取数据字典信息
        $data = $Db->table('system_dict_data')->select();
        return $this->api(200, '请求成功', ['items' => $data, 'pageInfo'=>['currentPage'=>1, 'total'=>count($data), 'totalPage'=>1]]);
    }
    
    /**
     * @RequestMapping(route="/admin/system/dataDict/save", method="post", title="字典数据添加")
    */
    public function system_dataDict_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        // 添加用户
        $result = $Db->table('system_dict_data')->insert($param);

        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '添加失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/dataDict/delete", method="delete", title="删除字典数据")
    */
    public function system_dataDict_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            // 删除用户
            $result = $Db->table('system_dict_data')->where('id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/system/dataDict/update", method="post", title="修改字典数据")
    */
    public function system_dataDict_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $arr = [];
        if(isset($param['type_id'])) $arr['type_id'] = $param['type_id'];
        if(isset($param['label'])) $arr['label'] = $param['label'];
        if(isset($param['value'])) $arr['value'] = $param['value'];
        if(isset($param['code'])) $arr['code'] = $param['code'];
        if(isset($param['sort'])) $arr['sort'] = $param['sort'];
        if(isset($param['status'])) $arr['status'] = $param['status'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $Db->table('system_dict_data')->where('id', $param['id'])->update($arr);
        
        return $this->api(200, '请求成功', []);

    }
    
    /**
     * @RequestMapping(route="/admin/setting/configGroup/index", method="get", title="获取配置类型信息")
    */
    public function setting_configGroup_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取配置类型
        $data = $Db->table('system_config_type')->select();
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/configGroup/save", method="post", title="添加配置类型信息")
    */
    public function setting_configGroup_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        // 设置配置参数
        $Db->table('system_config_type')->insert($param);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/configGroup/delete", method="delete", title="删除配置类型信息")
    */
    public function setting_configGroup_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        // 设置配置参数
        $Db->table('system_config_type')->where('id', $param['id'])->delete();
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/config/index", method="get", title="获取配置条目信息")
    */
    public function setting_config_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::param();
        
        $Db = new \houze\Db();
        // 获取配置类型
        $data = $Db->table('system_config_data')->where('group_id', $param['group_id'])->select();
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/config/save", method="post", title="添加配置条目信息")
    */
    public function setting_config_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        $Db->table('system_config_data')->insert($param);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/config/delete", method="delete", title="删除配置条目信息")
    */
    public function setting_config_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            $Db->table('system_config_data')->where('bolt', $v)->delete();
        }
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/config/update", method="post", title="更新数据条目信息")
    */
    public function setting_config_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        // 设置配置参数
        $Db->table('system_config_data')->where('bolt', $param['bolt'])->update($param);
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/config/updateByKeys", method="post", title="更新配置条目信息")
    */
    public function setting_config_updateByKeys() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $Db = new \houze\Db();
        // 设置配置参数
        foreach($param as $k => $v){
            $Db->table('system_config_data')->where('bolt', $k)->update(['value'=>$v]);
        }
        
        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/code/index", method="get", title="获取代码生成器首页信息")
    */
    public function setting_code_index() {
        // 权限校验
        $authInfo = $this->run();
        
        $Db = new \houze\Db();
        // 获取配置类型
        $data = $Db->table('system_code_data')->select();
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/code/preview", method="get", title="预览代码信息")
    */
    public function setting_code_preview() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::param();
        $Db = new \houze\Db();
        // 获取代码编辑器内容
        $preview = $Db->table('system_code_preview')->select();
        // 获取代码表类型数据
        $data = $Db->table('system_code_data')->where('id', $param['id'])->find();
        $columnList = [];
        foreach ($Db->getColumn($data['table_name']) as $k => $v){
            array_push($columnList, [
                'title' => $v['COLUMN_COMMENT'],
                'dataIndex' => $v['COLUMN_NAME'],
                'formType' => 'input'
            ]);
        }
        // 动态修改代码模板内容
        foreach ($preview as $k => $v){
            if($v['lang'] == 'html') $preview[$k]['code'] = $this->getCode('vue', $data, $columnList);
            if($v['lang'] == 'javascript') $preview[$k]['code'] = $this->getCode('js', $data, $columnList);
        }
        return $this->api(200, '请求成功', $preview);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/code/save", method="post", title="添加生成器首页信息")
    */
    public function setting_code_save() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        $Db = new \houze\Db();
        if(empty($Db->isTable($param['table_name']))) return $this->api(0, '数据表不存在', []);
        $data = $Db->table('system_code_data')->insert($param);
        return $this->api(200, '请求成功', $data);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/code/delete", method="delete", title="删除生成器首页信息")
    */
    public function setting_code_delete() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
    
        $Db = new \houze\Db();
        foreach($param['ids'] as $k => $v){
            $data = $Db->table('system_code_data')->where('id', $v)->find();
            if($data){
                // 删除代码文件
                \houze\File::del(ROOT_PATH . 'admin/src/views/'. $data['module_type'] . DS . $data['module_name'] . DS .'index.vue');
                \houze\File::del(ROOT_PATH . 'admin/src/api/'. $data['module_type'] . DS . $data['module_name'] .'.js');
            }
            // 删除数据库数据
            $result = $Db->table('system_code_data')->where('id', $v)->delete();
        }
        
        if($result){
            return $this->api(200, '请求成功', []);
        }else{
            return $this->api(0, '删除失败', []);
        }
    }
    
    /**
     * @RequestMapping(route="/admin/setting/code/update", method="post", title="修改生成器首页信息")
    */
    public function setting_code_update() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::raw();
        $param = json_decode($param, true);
        
        $arr = [];
        if(isset($param['table_des'])) $arr['table_des'] = $param['table_des'];
        if(isset($param['module_type'])) $arr['module_type'] = $param['module_type'];
        if(isset($param['module_name'])) $arr['module_name'] = $param['module_name'];
        if(isset($param['type'])) $arr['type'] = $param['type'];
        if(isset($param['options'])) $arr['options'] = $param['options'];
        if(isset($param['remark'])) $arr['remark'] = $param['remark'];
        
        $Db = new \houze\Db();
        $Db->table('system_code_data')->where('id', $param['id'])->update($arr);

        return $this->api(200, '请求成功', []);
    }
    
    /**
     * @RequestMapping(route="/admin/setting/code/create", method="post", title="生成代码信息")
    */
    public function setting_code_create() {
        // 权限校验
        $authInfo = $this->run();
        
        $param = \houze\Request::param();
        $Db = new \houze\Db();
        $data = $Db->table('system_code_data')->where('id', $param['id'])->find();
        $columnList = [];
        foreach ($Db->getColumn($data['table_name']) as $k => $v){
            array_push($columnList, [
                'title' => $v['COLUMN_COMMENT'],
                'dataIndex' => $v['COLUMN_NAME'],
                'formType' => 'input'
            ]);
        }
        // 写入代码文件
        \houze\File::auto_dir(ROOT_PATH . 'admin/src/views/'. $data['module_type'] . DS . $data['module_name']);
        $result = \houze\File::set(ROOT_PATH . 'admin/src/views/'. $data['module_type'] . DS . $data['module_name'] . DS .'index.vue', $this->getCode('vue', $data, $columnList));
        
        \houze\File::auto_dir(ROOT_PATH . 'admin/src/api/'. $data['module_type']);
        $result = \houze\File::set(ROOT_PATH . 'admin/src/api/'. $data['module_type'] . DS . $data['module_name'] .'.js', $this->getCode('js', $data, $columnList));
        if($result) return $this->api(200, '代码组件已成功生成，可添加菜单使用', $data);
        return $this->api(0, '生成失败', $data);
    }
    
    // 获取代码模板
    public function getCode($codeName, $data, $columnList){
        $vue =  '<template>' . PHP_EOL .
                '  <div class="ma-content-block lg:flex justify-between p-4">' . PHP_EOL .
                '    <!-- CRUD 组件 -->' . PHP_EOL .
                '      <ma-crud :crud="crud" :columns="columns" ref="crudRef">'. PHP_EOL .
                '      </ma-crud>'. PHP_EOL .
                '  </div>'. PHP_EOL .
                '</template>'. PHP_EOL .
                '<script setup>'. PHP_EOL .
                "import { ref, reactive } from 'vue'". PHP_EOL .
                "import ". $data['module_name'] ." from '@/api/". $data['module_type'] ."/". $data['module_name'] ."'". PHP_EOL .
                "import { Message } from '@arco-design/web-vue'". PHP_EOL .
                "import tool from '@/utils/tool'". PHP_EOL .
                "import * as common from '@/utils/common'". PHP_EOL .
                'const crudRef = ref()'. PHP_EOL .
                'const numberOperation = (newValue, id, numberName) => {'. PHP_EOL .
                '  '. $data['module_name'] .'.numberOperation({ id, numberName, numberValue: newValue }).then( res => {'. PHP_EOL .
                '    res.code && Message.success(res.msg)'. PHP_EOL .
                '  }).catch( e => { console.log(e) } )'. PHP_EOL .
                '}'. PHP_EOL .

                'const switchStatus = (statusValue, id, statusName) => {'. PHP_EOL .
                '  '. $data['module_name'] .'.changeStatus({ id, statusName, statusValue }).then( res => {'. PHP_EOL .
                '    res.code && Message.success(res.msg)'. PHP_EOL .
                '  }).catch( e => { console.log(e) } )'. PHP_EOL .
                '}'. PHP_EOL .


                'const crud = reactive({'. PHP_EOL .
                '  rowSelection: {'. PHP_EOL .
                '    showCheckedAll: true'. PHP_EOL .
                '  },'. PHP_EOL .
                "  searchLabelWidth: '75px',". PHP_EOL .
                "  pk: 'group_id',". PHP_EOL .
                '  operationColumn: true,'. PHP_EOL .
                '  operationWidth: 160,'. PHP_EOL .
                '  viewLayoutSetting: {'. PHP_EOL .
                "    layout: 'auto',". PHP_EOL .
                '    cols: 1,'. PHP_EOL .
                "    viewType: 'modal',". PHP_EOL .
                '    width: 600'. PHP_EOL .
                '  },'. PHP_EOL .
                '  api: '. $data['module_name'] .'.getList,'. PHP_EOL .
                '  recycleApi: '. $data['module_name'] .'.getRecycleList,'. PHP_EOL .
                '  add: {'. PHP_EOL .
                '    show: true,'. PHP_EOL .
                '    api: '. $data['module_name'] .'.save,'. PHP_EOL .
                "    auth: ['". $data['module_type'] .":". $data['module_name'] .":save']". PHP_EOL .
                '  },'. PHP_EOL .
                '  edit: {'. PHP_EOL .
                '    show: true,'. PHP_EOL .
                '    api: '. $data['module_name'] .'.update,'. PHP_EOL .
                "    auth: ['". $data['module_type'] .":". $data['module_name'] .":update']". PHP_EOL .
                '  },'. PHP_EOL .
                '  delete: {'. PHP_EOL .
                '    show: true,'. PHP_EOL .
                '    api: '. $data['module_name'] .'.deletes,'. PHP_EOL .
                "    auth: ['". $data['module_type'] .":". $data['module_name'] .":delete'],". PHP_EOL .
                '    realApi: '. $data['module_name'] .'.realDeletes,'. PHP_EOL .
                "    realAuth: ['". $data['module_type'] .":". $data['module_name'] .":realDeletes']". PHP_EOL .
                '  },'. PHP_EOL .
                '  recovery: {'. PHP_EOL .
                '    show: true,'. PHP_EOL .
                '    api: '. $data['module_name'] .'.recoverys,'. PHP_EOL .
                "    auth: ['". $data['module_type'] .":". $data['module_name'] .":recovery']". PHP_EOL .
                '  },'. PHP_EOL .
                '  import: {'. PHP_EOL .
                '    show: true,'. PHP_EOL .
                "    url: '". $data['module_type'] .'/'. $data['module_name'] ."/import',". PHP_EOL .
                "    templateUrl: '". $data['module_type'] .'/'. $data['module_name'] ."/downloadTemplate',". PHP_EOL .
                "    auth: ['". $data['module_type'] .":". $data['module_name'] .":import']". PHP_EOL .
                '  },'. PHP_EOL .
                '  export: {'. PHP_EOL .
                '    show: true,'. PHP_EOL .
                "    url: '". $data['module_type'] .'/'. $data['module_name'] ."/export',". PHP_EOL .
                "    auth: ['". $data['module_type'] .':'. $data['module_name'] .":export']". PHP_EOL .
                '  }' . PHP_EOL .
                "})". PHP_EOL .
                'const columns = reactive('. str_replace('}]', '}'.PHP_EOL.']', str_replace('{"', PHP_EOL.'  {"', json_encode($columnList, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))) .')'. PHP_EOL .
                "</script>". PHP_EOL .
                "<script> export default { name: '". $data['module_type'] .":". $data['module_name'] ."' } </script>";
                
                $js = "import { request } from '@/utils/request.js'

/**
 * 参数配置信息表 API JS
 */

export default {

  /**
   * 获取参数配置信息表分页列表
   * @returns
   */
  getList (params = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/index',
      method: 'get',
      params
    })
  },

  /**
   * 添加参数配置信息表
   * @returns
   */
  save (data = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/save',
      method: 'post',
      data
    })
  },

  /**
   * 更新参数配置信息表数据
   * @returns
   */
  update (id, data = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/update',
      method: 'put',
      data
    })
  },

  /**
   * 读取参数配置信息表
   * @returns
   */
  read (data = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/read',
      method: 'get',
      data
    })
  },

  /**
   * 将参数配置信息表删除，有软删除则移动到回收站
   * @returns
   */
  deletes (data) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/delete',
      method: 'delete',
      data
    })
  },

  /**
   * 从回收站获取参数配置信息表数据列表
   * @returns
   */
  getRecycleList (params = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/recycle',
      method: 'get',
      params
    })
  },

  /**
   * 恢复参数配置信息表数据
   * @returns
   */
  recoverys (data) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/recovery',
      method: 'put',
      data
    })
  },

  /**
   * 真实删除参数配置信息表
   * @returns
   */
  realDeletes (data) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/realDelete',
      method: 'delete',
      data
    })
  },

  /**
   * 更改参数配置信息表数据
   * @returns
   */
  changeStatus (data = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/changeStatus',
      method: 'put',
      data
    })
  },

  /**
   * 修改参数配置信息表数值数据，自增自减
   * @returns
   */
  numberOperation (data = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/numberOperation',
      method: 'put',
      data
    })
  },

  /**
    * 参数配置信息表导入
    * @returns
    */
  importExcel (data = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/import',
      method: 'post',
      data
    })
  },

  /**
   * 参数配置信息表下载模板
   * @returns
   */
  downloadTemplate () {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/downloadTemplate',
      method: 'post',
      responseType: 'blob'
    })
  },

  /**
   * 参数配置信息表导出
   * @returns
   */
  exportExcel (params = {}) {
    return request({
      url: '". $data['module_type'] ."/". $data['module_name'] ."/export',
      method: 'post',
      responseType: 'blob',
      params
    })
  },

}";
        
        if($codeName == 'vue') return $vue;
        if($codeName == 'js') return $js;
        return false;
    }
    
    // 统一获取用户菜单信息
    public function getUserMenuInfo($id=null){
        if(empty($id)) $id = 1;

        // 权限校验
        $authInfo = $this->run();
        if(isset($authInfo['user_id'])) $id = $authInfo['user_id'];
        
        $Db = new \houze\Db();
        // 获取用户信息
        $userInfo = $Db->table('system_user')->where('id', $id)->find();
        // 界面UI
        $userInfo['backend_setting'] = json_decode($userInfo['backend_setting'], true);
        // 获取菜单信息
        $menuInfo = $Db->table('system_menu')->select();
        // 父级菜单
        $parentMenu = \houze\Shop::getTree($menuInfo, 'id', 'parent_id', 'children', [0=>['value'=>'id', 'label'=>'name', 'meta'=>['type'=>'type', 'icon'=>'icon', 'title'=>'name', 'hidden'=>'is_hidden', 'hiddenBreadcrumb'=>'is_hidden', 'where'=>[['hidden', 1, true, false], ['hiddenBreadcrumb', 1, true, false]]]]]);
        
        // 获取用户菜单配置信息
        $config = [
            // 用户信息
            'user'=>$userInfo, 
            // 权限控制
            'codes'=>["*"],
            "roles"=> [
                "superAdmin"
            ], 
            // 用户菜单
            "routers"=> $parentMenu
        ];
        return $config;
    }
    
    // 统一获取目录
    public function getTree($type){
        if($type == 'dept') $table = 'system_dept';
        if($type == 'menu') $table = 'system_menu';
        if($type == 'post') $table = 'system_post';
        if($type == 'role') $table = 'system_role';
        
        $Db = new \houze\Db();
        // 获取部门信息
        $info = $Db->table($table)->field('id, name, parent_id')->select();
        
        $parent = \houze\Shop::getTree($info, 'id', 'parent_id', 'children', [0=>['value'=>'id', 'label'=>'name']]);
        return $parent;
    }
}